package view;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JComponent;

/**
 * Used for drawing the players' pieces
 */
public class Piece extends JComponent{
    private static final long serialVersionUID = 1L;
    private Color c;
    private int number;

    public Piece(Color c, Integer i){
        number = i;
        this.c = c;
        init();
    }

    private void init(){
        this.setPreferredSize(new java.awt.Dimension(25, 25));
        this.setVisible(true);
        this.setBounds(10, 10, 25, 25);
        this.setOpaque(true);
        repaint();
    }

    public void paintComponent(Graphics g){
        super.paintComponent(g);
        g.setColor(Color.black);
        g.fillRoundRect(0, 0, 25, 25, 5, 5);
        g.setColor(c);
        g.drawRect(3, 3, 19, 19);
        g.setColor(Color.white);
        g.drawString(""+number, 7, 16);
    }

    @Override
    public String toString(){
        return ""+number;
    }
}
